package com.pupil.down.system;

import java.util.HashSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: 系统设置
 * @Author: pupil
 * @Date: 2024/09/28 下午 4:11
 */
public class SysSettings {

    // 下载线程数量
    public static int DOWNLOAD_THREAD_NUM = 5;

    // 下载线程池
    public static final ExecutorService executor = Executors.newFixedThreadPool(DOWNLOAD_THREAD_NUM + 1);

    // 临时文件后缀
    public static String FILE_TEMP_SUFFIX = ".temp";

    // 文件下载路径
    public static String PATH = "/pupil-down/download/";

    // debug 开关
    public static Boolean DEBUG = false;

    // 存储支持的协议集合
    private static HashSet<String> PROTOCOL_PREFIX = new HashSet<>();


    static {
        PROTOCOL_PREFIX.add("thunder://");
        PROTOCOL_PREFIX.add("http://");
        PROTOCOL_PREFIX.add("https://");
    }


    // 判断是否支持该协议
    public static boolean isSupport(String url) {
        // 判断链接是否以指定前缀开头
        long count = PROTOCOL_PREFIX.stream().filter(prefix -> url.startsWith(prefix)).count();
        if (count == 0) {
            return false;
        }
        return true;
    }
}
